import { createWebHistory, createRouter } from 'vue-router'
import Login from '../components/Login.vue'
import App from '../App.vue'
import system_management from '../components/system_management.vue'
import Business_Management from '../components/Business_Management.vue'
import system_log from '../components/system_log.vue'
import Business_data from '../components/Business_data.vue'
import Check_in from '../components/Check_in.vue'
import Custom from '../components/custom.vue'
import Customer_Order_Report from '../components/Customer_Order_Report.vue'
import Data_statistics from '../components/data_statistics.vue'
import Front_desk_storage from '../components/Front_desk_storage.vue'
import House_price_management from '../components/House_price_management.vue'
import reservation from '../components/reservation.vue'
import Room_Management from '../components/Room_Management.vue'
import Member_Management from '../components/Member_Management.vue'




let router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            name: 'home',
            beforeEnter:((to,from,next)=>{
                if (!sessionStorage.getItem('token')) {
                    if (to.name === '/') {
                        next()
                    }
                    else {
                        router.push('/login')
                    }
                } else {
                    next()
                }
            }),
            component:()=>import('../components/Home.vue'),
            children: [
                {
                    path: '/system_management',
                    name: 'system_management',
                    component: system_management,
                    children: [
                        {
                            path: '/system_management/system_log',
                            name: 'system_log',
                            component: system_log
                        },
                        {
                            path: '/system_management/Member_Management',
                            name: 'Member_Management',
                            component: Member_Management
                        },
                        {
                            path: '/system_management/House_price_management',
                            name: 'House_price_management',
                            component: House_price_management
                        },
                        {
                            path: '/system_management/Room_Management',
                            name: 'Room_Management',
                            component: Room_Management
                        },

                    ]
                },
                {
                    path: '/Business_Management',
                    name: 'Business_Management',
                    component: Business_Management,
                    children: [
                        {
                            path: '/Business_Management/Check_in',
                            name: 'Check_in',
                            component: Check_in
                        },
                        {
                            path: '/Business_Management/reservation',
                            name: 'reservation',
                            component: reservation
                        },
                        {
                            path:'/Business_Management/Front_desk_storage',
                            name:'Front_desk_storage',
                            component:Front_desk_storage
                        },
                        {
                            path:'/Business_Management/custom',
                            name:"custom",
                            component:Custom
                        }
                    ]
                },
                {
                    path: '/Business_data',
                    name: 'Business_data',
                    component: Business_data,
                    children:[
                        {
                            path:'/Business_data/data_statistics',
                            name:'data_statistics',
                            component:Data_statistics
                        },
                        {
                            path:'/Business_data/Customer_Order_Report',
                            name:'Customer_Order_Report',
                            component:Customer_Order_Report
                        }
                    ]
                }
            ]
        },
        {
            path: '/login',
            name: 'login',
            component: Login
        },
        {
            path: '/admin',
            name: 'admin',
            component: () => import('../components/Admin.vue')
        }
    ]
})

export default router